﻿using System;
using Redmine.Laptop.Common.Constants;
using Redmine.Laptop.Reports.Factories.ReportFactories;
using Redmine.Laptop.Reports.ReportBuilders;

namespace Redmine.Laptop.Reports.Factories.ReportBuilderFactories
{
    internal class ReportBuilderFactory : IReportBuilderFactory
    {
        private readonly IReportFactory _reportFactory;

        private static ReportBuilderFactory _instance;
        public static ReportBuilderFactory GetInstance(IReportFactory reportFactory)
        {
            return _instance ?? (_instance = new ReportBuilderFactory(reportFactory)); 
        }
        
        private ReportBuilderFactory(IReportFactory reportFactory)
        {
            _reportFactory = reportFactory;
        }

        public ReportBuilder CreateBuilder(string report)
        {
            var type = (ReportType) Enum.Parse(typeof (ReportType), report);

            switch (type)
            {
                case ReportType.Timesheet:
                    return new TimesheetReportBuilder(_reportFactory);
                case ReportType.EmploymentRates:
                    return new EmploymentRatesReportBuilder(_reportFactory);
                default:
                    throw new ArgumentException(Constant.ExceptionMessage.UnknownReportType);
            }
        }
    }
}
